'''
Created on Oct 20, 2012

@author: Andre Dozier
'''

#import adodbapi  
import pyodbc 

class db:

    def __init__(self, database):        
        # constr = 'Provider=Microsoft.ACE.OLEDB.12.0; Data Source=%s' % database
        self.constr = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s' % database
    
        # connect to the database
        #conn = adodbapi.connect(constr)
        self.conn = pyodbc.connect(self.constr)
        
        # create a cursor
        self.cur = self.conn.cursor()
         
        
    def execute(self, querystring):
        # extract all the data
        self.cur.execute(querystring)
        result = self.cur.fetchall()
#        for item in result:
#            print item
        return result

    def close(self):
        # close the cursor and connection
        self.cur.close()
        self.conn.close()
            
if __name__ == "__main__":
    mdb = db(r"C:\Projects\IWPM\Models\scenarios\GCL_TwoBusSystem\Testing\Taylor_H_1E+8_M_500_S_3OUTPUT.mdb")
    table = mdb.execute(r"select * from LinksInfo")
    table2 = mdb.execute(r"select * from NodesInfo")
    mdb.close()
